<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>静态私有变量</title>
</head>
<body>
<header>
    <h1>静态私有变量</h1>
</header>
<main>
    <section>
        <blockquote>每天解决一个bug，进步一点点。。。</blockquote>
        <pre>
            //-------------START---------------------
                function fn(){
                    var name;
                }

                //var _name = name; //erro
            //-----------END------------------------

            //-------------START---------------------
               /* function people(_name,_age){
                    this.name = _name;
                    this.age  = _age;
                }*/

                function people(_name,_age){
                    var name = _name; //私有变量
                    var age  = _age;  //私有变量
                    var say  = function(){alert("我是一个方法")} //私有方法
                    //特权方法
                    this. _getName = function(){
                        return name;
                    }
                    this._setName = function(_name_){
                        name = _name_;
                    }
                    this._getAge  = function(){
                        return age;
                    }
                    this._setAge = function(_age_){
                        age = _age_;
                    }
                    this._getSay  = function(){
                        return say();
                    }
                }
                var zhangsn = new people("张三",20);
                alert(zhangsn._getName());
                alert(zhangsn._getAge());
                alert(zhangsn._getSay());
                zhangsn._setName("李四")
                alert(zhangsn._getName());
            // -----------END------------------------

            //-------------START---------------------
                (function(){
                    var name = "张三1"
                    User = function(){} //构造函数
                    User.prototype._getName = function(){
                        return name;
                    }
                    User.prototype._setName = function(_name){
                        name = _name;
                    }

                })();

                var VIPUser = new User();
                alert(VIPUser._getName())
                VIPUser._setName("李四1")
                //alert(VIPUser._getName())

                var VIPUser2 = new User();
                alert(VIPUser2._getName())
            // -----------END------------------------
        </pre>
    </section>
</main>
<footer>
    <a href="javascript:void(0)" onclick="window.close();">关闭</a>
    <abbr>powered by zhangxingong!!!</abbr>
</footer>
</body>
<script type="text/javascript">
    //-------------START---------------------
        function fn(){
            var name;
        }

        //var _name = name; //erro
    //-----------END------------------------

    //-------------START---------------------
       /* function people(_name,_age){
            this.name = _name;
            this.age  = _age;
        }*/

        function people(_name,_age){
            var name = _name; //私有变量
            var age  = _age;  //私有变量
            var say  = function(){alert("我是一个方法")} //私有方法
            //特权方法
            this. _getName = function(){
                return name;
            }
            this._setName = function(_name_){
                name = _name_;
            }
            this._getAge  = function(){
                return age;
            }
            this._setAge = function(_age_){
                age = _age_;
            }
            this._getSay  = function(){
                return say();
            }
        }
        var zhangsn = new people("张三",20);
        alert(zhangsn._getName());
        alert(zhangsn._getAge());
        alert(zhangsn._getSay());
        zhangsn._setName("李四")
        alert(zhangsn._getName());
    // -----------END------------------------

    //-------------START---------------------
        (function(){
            var name = "张三1"
            User = function(){} //构造函数
            User.prototype._getName = function(){
                return name;
            }
            User.prototype._setName = function(_name){
                name = _name;
            }

        })();

        var VIPUser = new User();
        alert(VIPUser._getName())
        VIPUser._setName("李四1")
        //alert(VIPUser._getName())

        var VIPUser2 = new User();
        alert(VIPUser2._getName())
    // -----------END------------------------

</script>
</html>